package com.xiaoba.shoppingcart.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xiaoba.common.log.annotation.Log;
import com.xiaoba.common.log.enums.BusinessType;
import com.xiaoba.common.security.annotation.RequiresPermissions;
import com.xiaoba.shoppingcart.domain.Cartitem;
import com.xiaoba.shoppingcart.service.ICartitemService;
import com.xiaoba.common.core.web.controller.BaseController;
import com.xiaoba.common.core.domain.Result;
import com.xiaoba.common.core.utils.poi.ExcelUtil;
import com.xiaoba.common.core.domain.Result;
import com.xiaoba.common.core.domain.Result;
import com.xiaoba.common.core.web.page.TableDataInfo;

/**
 * 购物车明细表Controller
 *
 * @author gd
 * @date 2024-06-07
 */
@RestController
@RequestMapping("/cartitem")
public class CartitemController extends BaseController
{
    @Autowired
    private ICartitemService cartitemService;

    /**
     * 查询购物车明细表列表
     */
    @RequiresPermissions("shoppingcart:cartitem:list")
    @GetMapping("/list")
    public Result<TableDataInfo> list(Cartitem cartitem)
    {
        startPage();
        List<Cartitem> list = cartitemService.selectCartitemList(cartitem);
        return getDataTable(list);
    }

    /**
     * 导出购物车明细表列表
     */
    @RequiresPermissions("shoppingcart:cartitem:export")
    @Log(title = "购物车明细表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Cartitem cartitem)
    {
        List<Cartitem> list = cartitemService.selectCartitemList(cartitem);
        ExcelUtil<Cartitem> util = new ExcelUtil<Cartitem>(Cartitem.class);
        util.exportExcel(response, list, "购物车明细表数据");
    }

    /**
     * 获取购物车明细表详细信息
     */
    @RequiresPermissions("shoppingcart:cartitem:query")
    @GetMapping(value = "/{detailId}")
    public Result getInfo(@PathVariable("detailId") Long detailId)
    {
        return success(cartitemService.selectCartitemByDetailId(detailId));
    }

    /**
     * 新增购物车明细表
     */
    @RequiresPermissions("shoppingcart:cartitem:add")
    @Log(title = "购物车明细表", businessType = BusinessType.INSERT)
    @PostMapping
    public Result add(@RequestBody Cartitem cartitem)
    {
        return toAjax(cartitemService.insertCartitem(cartitem));
    }

    /**
     * 修改购物车明细表
     */
    @RequiresPermissions("shoppingcart:cartitem:edit")
    @Log(title = "购物车明细表", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@RequestBody Cartitem cartitem)
    {
        return toAjax(cartitemService.updateCartitem(cartitem));
    }

    /**
     * 删除购物车明细表
     */
    @RequiresPermissions("shoppingcart:cartitem:remove")
    @Log(title = "购物车明细表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{detailIds}")
    public Result remove(@PathVariable Long[] detailIds)
    {
        return toAjax(cartitemService.deleteCartitemByDetailIds(detailIds));
    }
}
